//////////////////////////////////////////////////////////////////////////

#ifndef _NETWORK_PACKETS_H_
#define _NETWORK_PACKETS_H_

//////////////////////////////////////////////////////////////////////////

#include <queue>
#include <vector>
#include <ctime>

//////////////////////////////////////////////////////////////////////////

#include "common_types.h"

//////////////////////////////////////////////////////////////////////////


/** Network packet, that is sent by client to server
*
*  @author   Roman Pasechnik
*  @since    Jun 04th, 2009
*  @updated  Jun 23th, 2009
*/
struct ClientPacket
{
//////////////////////////////////////////////////////////////////////////


    /** Client identifier */
    unsigned char m_ClientID;


    /** Client keyboard state */
    unsigned int m_KeyFlags;


    /** Client mouse position */
    STM::ScrPosition m_MousePosition;


//////////////////////////////////////////////////////////////////////////


    /** Create packet from string */
    void FromStr( const char* _str );


    /** Convert packet to string */
    std::vector<char> ToStr() const;


    /** Comparison operators */
    bool operator==( const ClientPacket& _rhs );
    bool operator!=( const ClientPacket& _rhs );


    /** Get packet size in bytes */
    int Size() const;


//////////////////////////////////////////////////////////////////////////
};



/** Network packet, that is sent by server to client
*
*  @author   Roman Pasechnik
*  @since    Jun 04th, 2009
*  @updated  Jun 23th, 2009
*/
struct ServerPacket
{
//////////////////////////////////////////////////////////////////////////


    /** Packet creation time */
    clock_t m_CreationTime;


    /** Player coordinates */
    STM::ScrPositions m_Players;


    /** Bullet coordinates */
    STM::ScrPositions m_Bullets;


//////////////////////////////////////////////////////////////////////////


    /** Create packet from string */
    void FromStr( const char* _str );


    /** Convert packet to string */
    std::vector<char> ToStr() const;


    /** Comparison operators */
    bool operator==( const ServerPacket& _rhs );
    bool operator!=( const ServerPacket& _rhs );


    /** Get packet size in bytes */
    int Size() const;

private:

    int SaveData( const STM::ScrPositions& _objects, char* _mem ) const;
    int LoadData( STM::ScrPositions& _objects, const char* _mem );

//////////////////////////////////////////////////////////////////////////
};


/** [Utility type]: Queue of client packets */
typedef std::queue<ClientPacket> ClientPackets;


/** [Utility type]: Queue of server packets */
typedef std::queue<ServerPacket> ServerPackets;


//////////////////////////////////////////////////////////////////////////

#endif

//////////////////////////////////////////////////////////////////////////
